package com.zn.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zn.Vo.AdminAndCodeVo;
import com.zn.bean.Admin;
import com.zn.service.AdminService;
import com.zn.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 码农小周
 * @since 2023-05-12
 */
@Api(tags = "管理员相关操作")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService  adminService;
    /**
     * 管理员登录
     * @param adminAndCodeVo
     * @param request
     * @return
     */
    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public Result<Long> adminLogin(@RequestBody AdminAndCodeVo adminAndCodeVo, HttpServletRequest request){
        return adminService.login(adminAndCodeVo,request);
    }

    /**
     * 根据管理员ID获取用户信息
     * @param adminId
     * @return
     */
    @ApiOperation(value = "根据管理员ID获取用户信息")
    @GetMapping("/byAdminId")
    public Result<Admin> byAdminId(Long adminId){
        return adminService.byAdminId(adminId);
    }

    /**
     * 分页查询数据
     * @param page
     * @param pageSize
     * @param adminName
     * @return
     */
    @ApiOperation(value = "分页查询信息")
    @GetMapping("/page")
    public Result<Page<Admin>> pagSelect(Long page, Long pageSize, String adminName){
        return adminService.pagSelect(page,pageSize,adminName);
    }

    /**
     * 删除管理员
     * @param adminId
     * @return
     */
    @ApiOperation(value = "删除管理员数据")
    @DeleteMapping("/del")
    public Result<String> del(Long adminId){
        return adminService.del(adminId);
    }

    /**
     * 新增管理员
     * @param admin
     * @return
     */
    @ApiOperation(value = "新增管理员")
    @PostMapping("/addAdmin")
    public Result<String> addAdmin(@RequestBody Admin admin){
        return adminService.addAdmin(admin);
    }

    /**
     * 修改管理员信息
     * @param admin
     * @return
     */
    @ApiOperation(value = "修改管理员")
    @PostMapping("/editAdmin")
    public Result<String> editAdmin(@RequestBody Admin admin){
        return adminService.editAdmin(admin);
    }

    /**
     * 修改管理员状态
     * @param admin
     * @return
     */
    @ApiOperation(value = "修改管理员状态")
    @PutMapping("/editAdminStatus")
    public Result<String> editAdminStatus(@RequestBody Admin admin){
        return adminService.editAdminStatus(admin);
    }



    @ApiOperation(value = "重置密码")
    @PutMapping("/resetting")
    public Result<String> resetting(@RequestBody Admin admin){

        return adminService.resetting(admin);
    }



}
